﻿using NorthwindService;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using NorthwindModel.Models;
using NorthwindDAL.Repositories;
using NorthwindDAL;

namespace NorthwindTest
{ 
    /// <summary>
    ///This is a test class for CustomerServiceTest and is intended
    ///to contain all CustomerServiceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CustomerServiceTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for SaveCustomer
        ///</summary>
        [TestMethod()]
        public void SaveCustomerTest()
        {
            CustomerService target = new CustomerService();
            Customer customer = new Customer()
            {
                CustomerID = "WOLZV",
                CompanyName = "Wolski Zajazd",
                ContactName = "Zbyszek Piestrzeniewicz",
                ContactTitle = "Owner",
                Address = "ul. Filtrowa 68",
                City = "Warszawa",
                Region = null,
                PostalCode = "01-012",
                Country = "Poland",
                Phone = "(26) 642-7012",
                Fax = "(26) 642-7012",
                EntityState = System.Data.EntityState.Added
            };
            target.SaveCustomer(customer);

            Customer customerFound = target.GetCustomerByID("WOLZV");
            target.Dispose();
            Assert.AreNotEqual(null, customerFound);

            CustomerService target1 = new CustomerService();
            Customer customer1 = new Customer()
            {
                CustomerID = "WOLZV",
                CompanyName = "Wolski Zajazd V",
                ContactName = "Zbyszek Piestrzeniewicz V",
                ContactTitle = "Owner",
                Address = "ul. Filtrowa 68 V",
                City = "Warszawa",
                Region = null,
                PostalCode = "01-012",
                Country = "Poland",
                Phone = "(26) 642-7012",
                Fax = "(26) 642-7012",
                EntityState = System.Data.EntityState.Modified
            };
            target1.SaveCustomer(customer1);

            Customer customerFound1 = target1.GetCustomerByID("WOLZV");
            target1.Dispose();
            Assert.AreNotEqual(null, customerFound1);

            CustomerService target2 = new CustomerService();
            Customer customer2 = new Customer()
            {
                CustomerID = "WOLZV",
                CompanyName = "Wolski Zajazd",
                ContactName = "Zbyszek Piestrzeniewicz",
                ContactTitle = "Owner",
                Address = "ul. Filtrowa 68",
                City = "Warszawa",
                Region = null,
                PostalCode = "01-012",
                Country = "Poland",
                Phone = "(26) 642-7012",
                Fax = "(26) 642-7012",
                EntityState = System.Data.EntityState.Deleted
            };
            target2.SaveCustomer(customer2);

            Customer customerFound2 = target2.GetCustomerByID("WOLZV");
            target2.Dispose();
            Assert.AreEqual(null, customerFound2);            
        }

        /// <summary>
        ///A test for Clone of Customer
        ///</summary>
        [TestMethod()]
        public void CustomerCloneTest()
        {
            CustomerService target = new CustomerService();          

            Customer customerFound = target.GetCustomerByID("WOLZU");

            Customer customerCloned = customerFound.CloneEntity();
            customerCloned.Address = customerCloned.Address + " Test Clone";

            target.SaveCustomer(customerFound);
            customerFound = target.GetCustomerByID("WOLZU");
            target.Dispose();
            Assert.AreNotEqual("ul. Filtrowa 68 Test Clone", customerFound.Address);
        }

        /// <summary>
        ///A test for Clone of Customer
        ///</summary>
        [TestMethod()]
        public void CustomerCopyTest()
        {
            CustomerService target = new CustomerService();

            Customer customerFound = target.GetCustomerByID("WOLZU");

            Customer customerCloned = customerFound.CloneEntity();
            customerCloned.Address = customerCloned.Address + " Test Clone";
            customerFound.CopyProperties(customerCloned);
            target.SaveCustomer(customerFound);
            customerFound = target.GetCustomerByID("WOLZU");
            Assert.AreEqual("ul. Filtrowa 68 Test Clone", customerFound.Address);

            customerCloned.Address = "ul. Filtrowa 68";
            customerFound.CopyProperties(customerCloned);
            target.SaveCustomer(customerFound);
        }

        /// <summary>
        ///A test for getting EntitySet Name
        ///</summary>
        [TestMethod()]
        public void ENtityNameTest()
        {
            CategoryRepository cr = new CategoryRepository(new NorthwindContext());
            Assert.AreNotEqual(null, cr);
        }
    }
}
